package com.winning.ds.role.controller;

import com.winning.ds.common.entity.SysUserEntity;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/** @Author: nxs@winning.com.cn @Description: 递归构造树型结构 @Date: 2018-07-06 14:06:45 */
public class UserTreeUtil {

  public List<SysUserEntity> userCommon;
  public List<Object> list = new ArrayList<Object>();

  public List<Object> userTreeList(List<SysUserEntity> menuList) {
    this.userCommon = menuList;
    for (SysUserEntity mte : menuList) {
      Map<String, Object> mapArr = new LinkedHashMap<String, Object>();
      if ("0".equals(mte.getJgbm())) {
        mapArr.put("ID", mte.getZclsh());
        mapArr.put("rygh", mte.getRygh());
        mapArr.put("zc", mte.getZc());
        mapArr.put("name", mte.getRyxm());
        mapArr.put("ParentId", mte.getJgbm());
        mapArr.put("xb", mte.getXb());
        mapArr.put("dldm", mte.getDldm());
        mapArr.put("jsmc", mte.getJsmc());
        list.add(mapArr);
        list.addAll(menuChild(mte.getZclsh()));
      }
    }
    return list;
  }

  public List<?> menuChild(String munuid) {
    List<Object> lists = new ArrayList<Object>();
    for (SysUserEntity a : userCommon) {
      Map<String, Object> childArray = new LinkedHashMap<String, Object>();
      if (a.getJgbm().equals(munuid)) {
        childArray.put("ID", a.getZclsh());
        childArray.put("ParentId", a.getJgbm());
        childArray.put("rygh", a.getRygh());
        childArray.put("zc", a.getZc());
        childArray.put("name", a.getRyxm());
        childArray.put("xb", a.getXb());
        childArray.put("dldm", a.getDldm());
        childArray.put("jsmc", a.getJsmc());
        lists.add(childArray);
        lists.addAll(menuChild(a.getZclsh()));
      }
    }
    return lists;
  }
}
